<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    function Left(right) {
        switch (right) {
            case ')':
                return '(';
                break;
            case '}':
                return '{';
                break;
            case ']':
                return '[';
                break;


        }
    }

    function isValid(s) {
        //定义一个字符串，进行放元素
        let str = s[0];
        for (let i = 1; i < s.length; i++) {
            let num = str.length - 1;
            //判断是否为右括号，是右括号再进行判断
            if (s[i] == ')' || s[i] == '}' || s[i] == ']') {
                //如果匹配则删去字符串中的最后一个
                if (str[num] == Left(s[i])) {
                    str = str.slice(0, num);
                } else { //否则添加进进字符串
                    str += s[i];
                }
            } else { //不是右括号则添加进字符串
                str += s[i];
            }
        }
        //如果最终字符串为空表示全都匹配完成，则返回true
        if (str == '') {
            return true;
        } else { //否则返回false
            return false;
        }
    };
    console.log(isValid('{()())}'));
</script>

</html>